package org.linphone.activity;

import com.leehuubsd.yiyanzb.R;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

public class WebsiteActivity extends Activity implements OnClickListener {
	private WebView wv;
	private ProgressBar pb;
	private ImageView iv;
	private TextView tv;
	private String path, str;
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Toast.makeText(getApplicationContext(), "正在加载...", 0).show();
		setContentView(R.layout.activity_website_layout);
		Intent intent = getIntent();
		path = intent.getStringExtra("pathweb");
		str = intent.getStringExtra("title");
		wv = (WebView) findViewById(R.id.web);
		iv = (ImageView) findViewById(R.id.back_btn_website);
		tv = (TextView) findViewById(R.id.base_title_mid);
		pb = (ProgressBar) findViewById(R.id.pb);
		pb.setMax(100);
		tv.setText(str);
		iv.setOnClickListener(this);
		// wv.loadUrl("http://m.vcooline.com/70098");
		wv.getSettings().setJavaScriptEnabled(true);
		wv.setScrollBarStyle(0);
		WebSettings webSettings = wv.getSettings();
		webSettings.setAllowFileAccess(true);
		webSettings.setBuiltInZoomControls(true);
		if (TextUtils.isEmpty(path)) {
			wv.loadUrl("http://m.vcooline.com/leehuu");
		} else {
			wv.loadUrl(path);

		}
		// 加载数据

		wv.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				pb.setProgress(newProgress);
				if (newProgress == 100) {
					pb.setVisibility(View.GONE);
				}
				super.onProgressChanged(view, newProgress);
			}
		});

		wv.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// 调用拨号程序
				if (url.startsWith("mailto:") || url.startsWith("geo:")
						|| url.startsWith("tel:")) {
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri
							.parse(url));
					startActivity(intent);
				} else {
					// 当有新连接时，使用当前的 WebView
					view.loadUrl(url);
				}
				return true;
			}
		});

	}

	public boolean onKeyDown(int keyCoder, KeyEvent event) {
		if (wv.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {
			wv.goBack();
			return true;
		}
		return false;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.back_btn_website:
			finish();
			break;

		default:
			break;
		}

	}

}
